package cn.jlonely.xyhx.admin.controller;

import cn.jlonely.xyhx.admin.service.AnalysisService;
import cn.jlonely.xyhx.pojo.VoteData;
import cn.jlonely.xyhx.Exception.AnalysisException;
import cn.jlonely.xyhx.utils.AnalysisResult;
import cn.jlonely.xyhx.utils.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin/analysis")
@RequiredArgsConstructor
public class AnalysisController {
    private final AnalysisService analysisService;

    @PostMapping("/generate")
    public Result generateAnalysis(@RequestBody List<VoteData> data) {
        try {
            AnalysisResult result = analysisService.generateReport(data);
            return Result.success(result);
        } catch (AnalysisException e) {
            return Result.error("分析失败: " + e.getMessage());
        }
    }
}